<template>
    <div>
        <el-button @click="$router.push('/FormView')">添加</el-button>
        <el-table :data="tableData" style="width: 100%">
            <el-table-column prop="Id" label="编号" width="180">
            </el-table-column>
            <el-table-column prop="Name" label="表单名称" width="360">
            </el-table-column>
            <el-table-column prop="Describe" label="表单描述" width="720">
            </el-table-column>
            <el-table-column label="操作">
                <template slot-scope="scope">
                    <el-button type="text" @click="handleEdit(scope.$index, scope.row)">查看</el-button>
                    <el-button type="text" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>


<script>
import { FormQuery, FormDelete, FormUpdate, FormInsert } from '@/api/form.js'
export default ({
    data() {
        return {
            tableData: []
        }
    },
    methods: {
        //跳转编辑
        handleEdit(index, row) {
            //console.log(index, row);
            this.$router.push({name:'FormEdit',params:{data:row}})
        },
        //删除
        handleDelete(index, row) {
            //console.log(index, row);
            let arrIds=[];
            if(row==undefined){
                //批删
            }else{
                //单删
                arrIds.push(row.Id)
            }
            this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                FormDelete({ids:arrIds.toString()}).then(res => {
                    if (res.Code == 200) {
                        this.$message({
                            type: 'success',
                            message: '删除成功!'
                        });
                        this.getFormList();
                    } else {
                        this.$message.error(res.Message)
                    }
                })

            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });
        },
        //表单显示
        getFormList() {
            FormQuery().then(res => {
                this.tableData = res.Data
                //console.log(this.tableData);
            })
        }
    },
    created() {
        this.getFormList();
    }
})
</script>
